#!/bin/sh
export NOTIFY_URL="http://120.79.173.250:9201/JenkinsCallback"
export FTP_SERVER="cdn.hpplay.com.cn/jenkins_result"
export FTP_DIR="lebotest@120.76.155.128:/lebores/jenkins_result"
ftp_pwd="/lebores/jenkins_result"
echo this is android receiver apk build ...
sed -i 's/,/\n/g' user_config
source /etc/profile
rp_build_channel=`grep  build_channel user_config |awk -F '=' '{print $2}'`
rp_build_secret=`grep build_secret user_config |awk -F '=' '{print $2}'`
rp_jid=`grep jid user_config |awk -F '=' '{print $2}'`
echo user config as follow:
cat user_config
echo current path is `pwd`
echo get string build_channel=$rp_build_channel,build_secret=$rp_build_secret,jid=$rp_jid
apk_name=`ls /root/helen/rec_app_bak/version_713 |awk -F ".apk" '{print $1}'`
echo apk_name=$apk_name
if [ -f MultiChannelBuildTool/PythonTool/"$apk_name".apk ];then
	echo delete old apk
	rm MultiChannelBuildTool/PythonTool/"$apk_name".apk
fi 

if [ -d MultiChannelBuildTool/PythonTool/output_"$apk_name" ];then
	echo delete old out directory
	rm -rf MultiChannelBuildTool/PythonTool/output_"$apk_name"
fi
cp /root/helen/rec_app_bak/version_713/* MultiChannelBuildTool/PythonTool/
echo $rp_build_channel >MultiChannelBuildTool/PythonTool/info/channel.txt
echo channel.txt as follow:
cat MultiChannelBuildTool/PythonTool/info/channel.txt
cd MultiChannelBuildTool/PythonTool/
python MultiChannelBuildTool.py
upload_app=`ls output_"$apk_name"`
cd output_"$apk_name"
recapp_path=android_rec_app
echo will upload file "$upload_app" to ftp server dir $recapp_path
echo upload file info as follow:
du -sh $upload_app
start_time=`date +%s`
sshpass -p "lebo123"  scp -v "$upload_app" $FTP_DIR/$recapp_path/
#scp -o GSSAPIAuthentication=no -c arcfour128  -v "$upload_app" root@120.76.155.128:/lebores/jenkins_result/$recapp_path/
#sshpass -p "lebo123"  rsync -av --progress  "$upload_app" $FTP_DIR/$recapp_path/
cp -f /root/helen/scripts/expect_scp ./
#./expect_scp 120.76.155.128  "lebotest" "lebo123"  "$upload_app" $ftp_pwd/$recapp_path/
end_time=`date +%s`
echo 
cost=$(( $end_time - $start_time ))
echo "upload  Done. Total costs $cost seconds."
recapp_download="$FTP_SERVER/$recapp_path/$upload_app"
echo android receiver download path is $recapp_download
recapp_version=713
curl -H "Content-Type:application/json"  -X POST --data '{"dlinfo": [{"result_path": "'"$recapp_download"'","version": "'$recapp_version'","jid": "'$rp_jid'"}]}' $NOTIFY_URL 
